﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyWorkBlogDAL
{
   public partial class Blogroll
    {
       public static List<Blogroll> GetBlogrollsToList()
       {
           var query = (BlogDB.Blogrolls.Include("Blogs")
               .Select(n => n)).ToList();
           return query;
       }
       public static List<Blogroll> GetBlogrollsWithBlogIdToList(int blogId)
       {
           var query = (BlogDB.Blogrolls.Include("Blogs")
               .Where(n => n.Blog.BlogId == blogId)
               .Select(n => n)).ToList();
           return query;
       }

       public static int InsertBlogroll(Blogroll blogroll)
       {
           BlogDB.Blogrolls.Add(blogroll);
           return BlogDB.Save();

       }
       public static int UpdateBlogroll(Blogroll blogroll)
       {
           BlogDB.Blogrolls.AddOrUpdate(blogroll);
           return BlogDB.Save();

       }
       public static int DeleteBlogroll(Blogroll blogroll)
       {
           var query = BlogDB.Blogrolls
               .FirstOrDefault(n => n.BlogrollId == blogroll.BlogrollId);
           BlogDB.Blogrolls.Remove(query);
           return BlogDB.Save();

       }

    }
}
